<?php

namespace app\controller;

use app\model\GpsInfoModel;
use think\worker\Server;
use Workerman\Lib\Timer;
use think\facade\Db;

class RealTimeWorkerSocket extends Server
{
    protected $socket = 'websocket://0.0.0.0:25896';


    public function onMessage($connection, $data)
    {
        // var_dump($_GET);
        // 每2秒运行一次
        $timer_id = Timer::add(3, function () use ($data, $connection) {
            $info = GpsInfoModel::getInfoByCarNumber($data);
            $connection->send(json_encode($info));
        });

    }


}

